//
//  PopoverPresentationController.swift
//  swift_demo_weibo
//
//  Created by 杨兵 on 15/5/14.
//  Copyright (c) 2015年 bing. All rights reserved.
//

import UIKit

class PopoverPresentationController: UIPresentationController {
    
    lazy var dumming:UIView = {
        var v = UIView()
        v.backgroundColor = UIColor(white: 0, alpha: 0.2)
        
        // 添加手势识别,点击空白处关闭控制器
        let tap = UITapGestureRecognizer(target: self, action: "clickDummyView")
        v.addGestureRecognizer(tap)
        
        return v
    }()
    
    // 关闭图层
    func clickDummyView() {
        self.presentedViewController.dismissViewControllerAnimated(true, completion: nil)
    }
    
    
    override init(presentedViewController: UIViewController!, presentingViewController: UIViewController!) {
        // present ed ViewController 是展现的视图
        // present ing ViewController 貌似是空的,不知道干啥的
        super.init(presentedViewController: presentedViewController, presentingViewController: presentingViewController)
    }
    
    
    override func containerViewWillLayoutSubviews() {
        super.containerViewWillLayoutSubviews()
        // 插入视图,插入到最底层
        dumming.frame = containerView.frame
        containerView.insertSubview(dumming, atIndex: 0)
        
        presentedView().frame = CGRectMake(100, 56, 200, 300)
        
    }
    
    
    
    
}
